package com.mmsj;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.Bundle;
import android.util.Log;

import androidx.activity.EdgeToEdge;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class MyBookDBHelper  extends SQLiteOpenHelper {


        private static final String DATABASE_NAME = "fDB.db";
        private static final int DATABASE_VERSION = 1;

        private static com.mmsj.MyDBHelper helper;


        public static com.mmsj.MyDBHelper getInstance(Context context) {
            if (helper == null) {
                helper = new com.mmsj.MyDBHelper(context, DATABASE_NAME, null, DATABASE_VERSION);
            }
            return helper;
        }

        public MyBookDBHelper(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version) {
            super(context, DATABASE_NAME, factory, DATABASE_VERSION);
        }

        // 首次创建数据库时调用，在该方法中创建表
        @Override
        public void onCreate(SQLiteDatabase db) {
            // 创建表
            String sql = "create table if not exists user(id integer primary key autoincrement,username text,password text,phone text)";
            db.execSQL(sql);
            // 数据库路径
            String path = db.getPath();
            Log.d("my-log","数据库路径："+path);
            Log.d("my-log","user表创建成功");
        }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

        }
    }
